#XML BEAST CODE: unfinished





from elementtree.ElementTree import *

XML = parse("/Users/will/Documents/rbcL Phylogeny/testPython.xml")
tree = XML.getroot()
cladeList=[["EF683674 Aglais io cytochrome oxidase subunit I (COI) gene","EF683676 Aglais urticae cytochrome oxidase subunit I (COI) gene","FJ663263 Anthocharis cardamines voucher 2005-LOWA-322 cytochrome oxidase subunit 1 (COI) gene","EF534090 Apatura iris cytochrome oxidase subunit I (COI) gene","AY090211 Aphantopus hyperantus isolate 2-1 cytochrome oxidase subunit I (COI) gene","DQ922852 Argynnis adippe voucher NW95-4 cytochrome oxidase subunit I (COI) gene","DQ922860 Argynnis aglaja voucher NW76-15 cytochrome oxidase subunit I (COI) gene","AY090200 Argynnis paphia voucher NW76-12 cytochrome oxidase subunit I (COI) gene","AY350456 Aricia agestis cytochrome oxidase subunit I (COI) gene"]]
cladeNames=['x']

i = 0
for clade in cladeList:
	temp=Element("taxa", id=cladeNames[i])
	temp.tail="\n"
	i = i + 1
	for sp in clade:
		subTemp=Element("taxon", idref=sp)
		subTemp.tail="\n"
		temp.append(subTemp)
	
	tree.insert(1, temp)

for i in range(len(tree)):
	if tree[i].tag=="coalescentTree":
		tree[i].remove(tree[i][0])
		temp=Element("constrainedTaxa")
		SubElement(temp, "taxa", idref="taxa")
		for clade in cladeNames:
			subTemp=Element("tmrca", monophyletic="true")
			SubElement(subTemp, "taxa", idref=clade)
			temp.append(subTemp)
		tree[i].append(temp)
	
	if tree[i].tag=="treeLikelihood":
		for clade in cladeNames:
			temp=Element("tmrcaStatistic", id="tmrca_" + clade, includeStem="false")
			subTemp=Element("mrca")
			SubElement(subTemp, "taxa", idref=clade)
			temp.append(subTemp)
			SubElement(temp, "treeModel", idref="treeModel")
			tree[i].append(temp)
		for clade in cladeNames:
			temp=Element("monophylyStatistic", id="monophyly_" + clade, includeStem="false")
			subTemp=Element("mrca")
			SubElement(subTemp, "taxa", idref=clade)
			temp.append(subTemp)
			SubElement(temp, "treeModel", idref="treeModel")
			tree[i].append(temp)
	
	if tree[i].tag=="prior":
		temp=Element("boolanLikelihood")
		for clade in cladeNames:
			SubElement(temp, "monophylyStatistic", idref="monophyly_"+clade)
		tree[i].append(temp)
	
	if tree[i].tag=="logTree":
		for clade in cladeNames:
			SubElement(tree[i], "tmrcaStatistic", idref="tmarca_"+clade)

indent(tree)
ElementTree(tree).write("/Users/will/Documents/rbcL Phylogeny/testPythonOut.xml")

